package com.fenghongzhang.test;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class FengMatrix extends View {
    Bitmap bitmap;
    Matrix matrix;
    Paint paint;
    public FengMatrix(Context context) {
        super(context);
        init();
    }


    public FengMatrix(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FengMatrix(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    private void init() {
        matrix = new Matrix();
        paint = new Paint();

         bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(bitmap,matrix,paint);
    }

    public void tran(int x ,int y){
        matrix.reset();
        matrix.setTranslate(x,y);
        invalidate();
    }
}
